<template>
  <uni-nav-bar :title="TeamInfo.KeyCustom.name" left-icon="left" @clickLeft="navBack" :fixed="true"
    statusBar></uni-nav-bar>
  <view class="package">
    <view class="space-between">
      <view>大客户名称</view>
      <view>{{TeamInfo.KeyCustom.name}}({{TeamInfo.KeyCustom.id}})</view>
    </view>
    <view class="space-between top">
      <view>剩余额度</view>
      <view>{{TeamInfo.KeyCustom.quota}}元</view>
    </view>
    <view class="space-between top" @click="change()">
      <view>结算价</view>
      <view class="center">{{TeamInfo.KeyCustom.jiesuan_price}}元
        <uni-icons type="forward" size="20"></uni-icons>
      </view>
    </view>
  </view>
  <view class="package space-between ability" style="background: transparent;padding: 0px;">
    <view v-for="item in list" :key="item" @click="navTo(item.push)">{{item.name}}</view>
  </view>
  <!-- 填写结算价 -->
  <Price @submit="submit" ref="AddPrice" type="jiesuan"></Price>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import Price from '@c/administrator/BulletBox/price.vue';
  import { navBack, navTo } from '@/utils/navigator';
  import { showLoading, errorToast, successToast } from '@/utils/prompt';
  import { toPublish } from '@mqtt';
  import { onLoad, onUnload } from '@dcloudio/uni-app';
  import { information } from '@/stores/administrator';
  const TeamInfo = information();
  const AddPrice = ref(null)
  const list = [{ name: '加注机', push: '' },
  { name: '司机价', push: '' },
  { name: '加注订单', push: 'administrator/keyaccount/orderList' },
  { name: '价格组', push: 'administrator/keyaccount/priceList' },
  { name: '车友', push: 'administrator/keyaccount/carFriend' },
  { name: '后台账号', push: 'administrator/keyaccount/account' },
  { name: '大客户绑定码', push: 'administrator/keyaccount/binding' }]
  onLoad((pearm) => {
    TeamInfo.geKeyIn(pearm.id)
    list[0].push = 'administrator/keyaccount/fillList?id=' + pearm.id
    list[1].push = 'administrator/keyaccount/addPrice?type=add&id=' + pearm.id
  })
  function change() {
    AddPrice.value.openBankPad()
  }
  // 填写结算价
  function submit(num : number) {
    showLoading()
    const payload = {
      price: num,
      customers_id: Number(TeamInfo.KeyCustom.id)
    };
    toPublish(
      'control/editCustomersJiesuanPrice',
      payload,
      (obj : any) => {
        const { code, msg } = obj;
        if (code === 1) {
          TeamInfo.geKeyIn(TeamInfo.KeyCustom.id)
          successToast(msg)
        } else {
          errorToast(msg)
        }
      }
    );
  }
  onUnload(() => {
    uni.removeStorageSync('KeyCustom')
  })
</script>

<style scoped lang="less">
  .top {
    margin-top: 10rpx;
  }

  .ability {
    flex-wrap: wrap;

    view {
      width: 48.5%;
      height: 102rpx;
      background: #FFFFFF;
      border: 1px solid #EEF3F7;
      border-radius: 6px;
      text-align: center;
      line-height: 102rpx;
      margin-bottom: 15rpx;
    }
  }
</style>